package com.charlotte.servidor;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

/**
 *
 * @author law
 */
@Path("ws")
public class WebService 
{
    
    @GET @Path("ip") @Produces({MediaType.TEXT_PLAIN})
    public Response $ip(@Context HttpServletRequest request)
    {
        try
        {
            return Response.status(Status.OK).language(request.getLocale()).
                    entity(request.getRemoteAddr()).build();
        }
        catch(Exception e)
        {
            return Response.status(Response.Status.BAD_REQUEST).
                    entity("error = "+e.getMessage()).language(request.getLocale()).build();
        }
    }
    
    @GET @Path("ua") @Produces({MediaType.TEXT_PLAIN})
    public Response $ua(@Context HttpServletRequest request)
    {
        try
        {
            return Response.status(Status.OK).language(request.getLocale()).
                    entity(request.getHeader("User-Agent")).build();
        }
        catch(Exception e)
        {
            return Response.status(Response.Status.BAD_REQUEST).
                    entity("error = "+e.getMessage()).language(request.getLocale()).build();
        }
    }
    
}
